Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add SwapToast component #1281

Merged
merged 10 commits into from
Sep 24, 2024
Merged

feat: Add SwapToast component #1281

merged 10 commits into from
Sep 24, 2024

Conversation

abcrane123
Copy link
Contributor

@abcrane123 abcrane123 commented Sep 19, 2024

What changed? Why?

  • add SwapToast component and display on success

Notes to reviewers

How has it been tested?

Copy link

vercel bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
onchainkit-coverage ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 24, 2024 3:07am
onchainkit-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 24, 2024 3:07am
onchainkit-routes ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 24, 2024 3:07am

@@ -70,6 +70,9 @@ export function SwapProvider({
},
}); // Component lifecycle

const [isToastVisible, setIsToastVisible] = useState(false);
const [transactionHash, setTransactionHash] = useState('');
Copy link
Contributor

@alessey alessey Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on combining these to store toast content in isToastVisible? would allow the us to use the toast for other any information instead of being strictly tied to success/transactionHash

i.e. const [toastContent, setToastContent] = useState<bool | ReactNode>(false);
setToastContent(<SuccessToast transactionHash=""/>);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm well we don't really need to store the whole component because theyre rendering SwapToast as a child (following the pattern of the rest of the components) right? also we could use the toast for other information by checking the isToastVisible value along with an error state, for example, stored in lifeCycleStatus. The reason i had to do the extra state for transactionHash is because we immediately reset the lifeCycleStatus to init after calling onsuccess.

curious what the rest of the team thinks about this @0xAlec @cpcramer

my thinking is that if we want to do something like you're suggesting we should follow the same pattern with TransactionToast and maybe that should be a follow up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense regardless to not have the toast showing content directly from lifecycle. If we want to toast an error, we don't want the toast to clear if the error clears, but I don't want to end up with a bunch of separate states to hold different things we want to show in the toast. my initial thought was that success toast could store transactionHash in its internal state and encapsulate the chainExplorer logic, and then just get displayed as a child of the toast.

background.default,
'flex animate-enter items-center justify-between rounded-lg',
'p-2 shadow-[0px_8px_24px_0px_rgba(0,0,0,0.12)]',
'-translate-x-2/4 fixed z-20',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the animate in from the right seems weird, also, should this be pegged to the swap component vs. the window?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i noticed that as well but it seems like only an issue with playground. The same issue appears for transaction toast which looks fine on docs site.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so will investigate but it appears like it was an existing issue with how we style our toasts

@@ -0,0 +1,12 @@
export function getToastPosition(position: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Comment on lines +216 to +217
isToastVisible?: boolean;
setIsToastVisible?: (visible: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a larger discussion, but how are we determining when state should live / be handled in the SwapContext vs. LifecycleStatus shared? cc @alessey

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the toasts are a case where we cannot rely on lifecycle status in case we want to display a toast longer than a lifecycle status persists. Although I would prefer to encapsulate the toast state within its own component or a single toast state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abcrane123 abcrane123 merged commit fba38e0 into main Sep 24, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants